#include "heroplane.h"
#include "config.h"

HeroPlane::HeroPlane()
{
    //初始化加载飞机资源
    m_Plane.load(":/res/me1");
    //初始化飞机坐标
    m_X=(GAME_WIDTH-m_Plane.width())*0.5;
    m_Y=GAME_HEIGHT-m_Plane.height();

    //初始化判定边界
    m_Rect.setWidth(m_Plane.width());
    m_Rect.setHeight(m_Plane.height());
    m_Rect.moveTo(m_X,m_Y);
}

void HeroPlane::shoot()
{
    //累加时间间隔变量
    m_recorder++;
    if(m_recorder<BULLET_SPACE){
        return;
    }

    m_recorder=0;
    for(int i=0;i<BULLET_NUM;i++){
        if(m_bullets[i].m_Free){
            m_bullets[i].m_Free=false;
            m_bullets1[i].m_Free=false;
            m_bullets[i].m_X=m_X+15;
            m_bullets[i].m_Y=m_Y+40;
            m_bullets1[i].m_X=m_X+80;
            m_bullets1[i].m_Y=m_Y+40;
            break;
        }
    }
}

void HeroPlane::setPosition(int x, int y)
{
    m_X=x;
    m_Y=y;
    m_Rect.moveTo(m_X,m_Y);
}
